package models;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import model.entityes.exception.StringContentException;

import play.db.ebean.Model;

/**
 * 
 * @author pocteg
 * 
 */
@Entity
@Table(name = "string_content")
public class StringContent extends Model
{

    /**
     * ----PRIVATE-----------ATTRIBUTS-----------INSTANCE-----------------------
     * ----
     */

    /**
     * ----PRIVATE-----------ATTRIBUTS-----------STATIC-------------------------
     * ----
     */

    private static final long serialVersionUID = 1L;

    /**
     * ----PROTECTED---------ATTRIBUTS-----------INSTANCE-----------------------
     * ----
     */

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    protected long id;
    protected long id_structure;
    protected long id_node;
    protected long id_type;
    @Column(columnDefinition = "LONGTEXT")
    protected String content;
    // protected String validationString;
    /**
     * ----PROTECTED---------ATTRIBUTS-----------STATIC-------------------------
     * ----
     */

    protected final static String ID = "id";
    protected final static String ID_STRUCTURE = "id_structure";
    protected final static String ID_NODE = "id_node";
    protected final static String ID_TYPE = "id_type";
    protected final static String CONTENT = "content";

    /**
     * ----PUBLIC------------ATTRIBUTS-----------INSTANCE-----------------------
     * ----
     */

    /**
     * ----PUBLIC------------ATTRIBUTS-----------STATIC-------------------------
     * ----
     */

    public static Model.Finder<Long, StringContent> find = new Model.Finder<Long, StringContent>(Long.class, StringContent.class);

    /**
     * ----CONSTRUCTORS--------------------------------------------------------
     * ----
     */

    /**
     * ----PRIVATE-----------METHOD-----------INSTANCE--------------------------
     * ----
     */

    /**
     * ----PRIVATE-----------METHOD-----------STATIC----------------------------
     * ----
     */

    /**
     * ----PROTECTED---------METHOD-----------INSTANCE--------------------------
     * ----
     */

    /**
     * ----PROTECTED---------METHOD-----------STATIC----------------------------
     * ----
     */

    /**
     * ----PUBLIC------------METHOD-----------INSTANCE--------------------------
     * ----
     */

    /**
     * ----PUBLIC------------METHOD-----------STATIC----------------------------
     */

    /**
     * Return exist StringContent by id.
     * 
     * @param id
     * @return
     * @throws StringContentException
     */
    public static StringContent getById(Long id) throws StringContentException
    {
	try
	{
	    if (id == null) throw StringContentException.errorIdEqNull();
	    return StringContent.find.byId(id);
	}
	catch (Exception e)
	{
	    throw StringContentException.getExceptionWhitUserMessage("Error(id = " + id.toString() + "): " + e.getMessage());
	}
    }

    public static List<StringContent> search(String q)
    {
	return StringContent.find.where().like(StringContent.CONTENT, "%"+q+"%").findList();
    }

    /**
     * ----GETTERS--&--SETTERS--------------------------------------------------
     */

    public long getId()
    {
	return id;
    }

    public void setId(long id)
    {
	this.id = id;
    }

    public long getId_structure()
    {
	return id_structure;
    }

    public void setId_structure(long id_structure)
    {
	this.id_structure = id_structure;
    }

    public long getId_node()
    {
	return id_node;
    }

    public void setId_node(long id_node)
    {
	this.id_node = id_node;
    }

    public long getId_type()
    {
	return id_type;
    }

    public void setId_type(long id_type)
    {
	this.id_type = id_type;
    }

    public String getContent()
    {
	return content;
    }

    public void setContent(String content)
    {
	this.content = content;
    }
}
